<?php
function check_session($member_type)
{
	global $website_home,$DB_site,$_GET,$_POST,$_COOKIE,$session_logout;
	$sess = ($_GET["sess"] != "") ? $_GET["sess"] : ( ($_POST["sess"] != "") ? $_POST["sess"] : $_COOKIE["sess"]);
	if (!($sess)) {header("Location: $website_home");}
	else
	{
		$array = $DB_site->query_first("SELECT member_id,email,session_id FROM sessions WHERE session_id='$sess' AND member_type='$member_type'");
		if ($array)
		{
		  setcookie("sess",$sess,time()+$session_logout*60);
			return $array;
		}
		else 
		{
		  setcookie("sess","");
			$result = $DB_site->query("DELETE FROM sessions WHERE session_id='$sess'");
			$msg = "Login has expired. Please login again";
			header("Location: $website_home?msg=".urlencode($msg));
		}
	}	
}

?>
